package com.tiancheng.trade.settlement.mapper.settlement;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tiancheng.trade.settlement.exception.BusinessException;
import com.tiancheng.trade.settlement.mapper.TYBaseMapper;
import com.tiancheng.trade.settlement.model.settlement.PaymentOrderFinish;
import com.tiancheng.trade.settlement.vo.settlement.admin.PaymentBillDetailQuery;
import com.tiancheng.trade.settlement.vo.settlement.admin.PaymentBillQueryVO;
import com.tiancheng.trade.settlement.vo.settlement.admin.PaymentOldSystemVO;
import com.tiancheng.trade.settlement.vo.settlement.admin.res.PaymentBillListResVO;
import com.tiancheng.trade.settlement.vo.settlement.admin.res.PaymentBillSummaryResVO;
import com.tiancheng.trade.settlement.vo.settlement.admin.res.SubOrderResVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Auther: liudong
 * @Date: 2024/3/31 10:24
 * @Param ${tags}
 * @Description:
 */
@Repository
public interface PaymentOrderFinishMapper extends TYBaseMapper<PaymentOrderFinish> {

    int batchSaveFinishOrders(@Param("basics") List<PaymentOrderFinish> basics);


    int updateOldSystemDataStatus(@Param("vo") PaymentOldSystemVO vo);


    /**
     * 查询正确对账数据
     *
     * @param flowId
     * @return
     */
    List<PaymentOrderFinish> getFinishBankOrders(List<String> flowId);

    /**
     * 查询异常数据
     *
     * @param flowId
     * @return
     */
    List<PaymentOrderFinish> getErrorBankOrders(List<String> flowId);

    /**
     * 银行侧为空时，查询对账中心待对账订单是否有待对账数据，记录数据未匹配异常
     *
     * @return
     */
    List<PaymentOrderFinish> getUnusualOrders();

    /**
     * 已完成对账表获取异常数据，flow_Id为空的数据
     */
    List<PaymentOrderFinish> getUnusualBankOrders();


    IPage<PaymentBillSummaryResVO> querySummaryView(Page<?> page, @Param("vo") PaymentBillQueryVO paymentBillQueryVO) throws BusinessException;

    /**
     * 流水明细对账查询
     *
     * @param page
     * @param paymentBillQueryVO
     * @return
     * @throws BusinessException
     */
    IPage<PaymentBillListResVO> queryPaymentBillFinish(Page<?> page, @Param("vo") PaymentBillDetailQuery paymentBillQueryVO) throws BusinessException;

    /**
     * 流水明细对账查询导出使用
     *
     * @param paymentBillQueryVO
     * @return
     * @throws BusinessException
     */
    List<PaymentBillListResVO> queryPaymentBillFinish(@Param("vo") PaymentBillDetailQuery paymentBillQueryVO) throws BusinessException;

    /**
     * 按时间获取银行实收金额
     */
    List<SubOrderResVO> getReceiptList(@Param("date") String date);

    /**
     * 无合同信息
     * 按时间获取银行实收金额
     */
    List<SubOrderResVO> getNoContractReceiptList(@Param("date") String date);

    /**
     * 手工修改后更新流水状态
     *
     * @param flowId
     * @return
     */
    int updateStatus(@Param("flowId") String flowId);

    /**
     * 流水对账退款数据对账
     *
     * @param refundIds
     * @return
     */
    List<PaymentOrderFinish> getFinishRefundBankOrders(List<String> refundIds);

}
